﻿using AutoMapper;
using StarsAdmin.Application.Menu.Dtos;
using StarsAdmin.Core.DB.Entities;
using StarsAdmin.Core.Extensions;
using StarsAdmin.Core.Models;

namespace StarsAdmin.Application.Menu.Mappings
{
    public class MenuAutoMapperProFile : Profile
    {
        public MenuAutoMapperProFile()
        {
            CreateMap<Page<MenuEntity>, Page<MenuDto>>();
            CreateMap<AddMenuInput, MenuEntity>();
            CreateMap<UpdateMenuInput, MenuEntity>();
            CreateMap<MenuEntity, MenuDto>()
                .ForMember(dest => dest.ParentName, opt => opt.MapFrom(src => src.Parent.Name))
                .ForMember(dest => dest.AuthFields, opt => opt.MapFrom(src => src.Apis.Select(e => e.Path)))
                .ForMember(dest => dest.ApiIds, opt => opt.MapFrom(src => src.Apis.Select(e => e.Id)));
            CreateMap<MenuEntity, ExportMenuDto>()
            .ForMember(dest => dest.ParentName, opt => opt.MapFrom(src => src.Parent.Name))
            .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type.GetDescription()));
        }
    }
}